﻿namespace HRM.CORE
{
    using DevExpress.XtraBars;
    using DevExpress.XtraEditors;
    using APP.HELPER;
    using Common.Class; using APP.HELPER.Utils.Language; using Security.Security; using Dictionary.ERP;
    using HRM.CORE;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;

    public class xfmRewardAdd : XtraForm
    {
        private IContainer components;
        public RowClickEventArgs m_RowClickEventArgs;
        private xucRewardAdd ucAdd;

        public event AddedEventHander Added;

        public event UpdatedEventHander Updated;

        public xfmRewardAdd()
        {
            this.components = null;
            this.InitializeComponent();
        }

        public xfmRewardAdd(Actions Action)
        {
            this.components = null;
            this.InitializeComponent();
            this.Init();
            this.ucAdd.Status = Action;
            this.ucAdd.SetData(new HRM_REWARD().NewID());
            this.Text = ((SysOption.Language == "EN") ? "New " : "Th\x00eam ") + this.Text;
        }

        public xfmRewardAdd(Actions Action, HRM_REWARD Item)
        {
            this.components = null;
            this.InitializeComponent();
            this.Init();
            this.ucAdd.Status = Action;
            if (Action == Actions.Update)
            {
                this.ucAdd.SetData(Item);
                this.Text = ((SysOption.Language == "EN") ? "Edit " : "Cập Nhật ") + this.Text;
            }
            else if (Action == Actions.Delete)
            {
                this.ucAdd.SetData(Item.RewardCode);
            }
        }

        public void Delete()
        {
            this.ucAdd.Delete();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void Init()
        {
            this.ucAdd.CancelClick += new ButtonClickEventHander(this.ucAdd_CancelClick);
            this.ucAdd.Success += new xucRewardAdd.SuccessEventHander(this.ucAdd_Success);
            this.Text = (SysOption.Language == "EN") ? "HRM_REWARD" : this.Text;
        }

        private void InitializeComponent()
        {
            MenuButton button = new MenuButton();
            ItemCommand command = new ItemCommand();
            ItemCommand command2 = new ItemCommand();
            ItemCommand command3 = new ItemCommand();
            ItemCommand command4 = new ItemCommand();
            ItemCommand command5 = new ItemCommand();
            ItemCommand command6 = new ItemCommand();
            ItemCommand command7 = new ItemCommand();
            ItemCommand command8 = new ItemCommand();
            ItemCommand command9 = new ItemCommand();
            ItemCommand command10 = new ItemCommand();
            ItemCommand command11 = new ItemCommand();
            ItemCommand command12 = new ItemCommand();
            ItemCommand command13 = new ItemCommand();
            ItemCommand command14 = new ItemCommand();
            ItemCommand command15 = new ItemCommand();
            ItemCommand command16 = new ItemCommand();
            ItemCommand command17 = new ItemCommand();
            ItemCommand command18 = new ItemCommand();
            ItemCommand command19 = new ItemCommand();
            ItemCommand command20 = new ItemCommand();
            ItemCommand command21 = new ItemCommand();
            ItemCommand command22 = new ItemCommand();
            ItemCommand command23 = new ItemCommand();
            ItemCommand command24 = new ItemCommand();
            ItemCommand command25 = new ItemCommand();
            ItemCommand command26 = new ItemCommand();
            ItemCommand command27 = new ItemCommand();
            ItemCommand command28 = new ItemCommand();
            ItemCommand command29 = new ItemCommand();
            this.ucAdd = new xucRewardAdd();
            base.SuspendLayout();
            this.ucAdd.Dock = DockStyle.Fill;
            this.ucAdd.IsClose = CloseOrNew.None;
            this.ucAdd.Location = new Point(0, 0);
            this.ucAdd.Name = "ucAdd";
            this.ucAdd.NotSave = false;
            command.Caption = "";
            command.Enable = false;
            command.Visibility = BarItemVisibility.Never;
            button.Add = command;
            command2.Caption = "";
            command2.Enable = false;
            command2.Visibility = BarItemVisibility.Never;
            button.Cancel = command2;
            command3.Caption = "";
            command3.Enable = false;
            command3.Visibility = BarItemVisibility.Never;
            button.Change = command3;
            command4.Caption = "";
            command4.Enable = false;
            command4.Visibility = BarItemVisibility.Never;
            button.Close = command4;
            command5.Caption = "";
            command5.Enable = false;
            command5.Visibility = BarItemVisibility.Never;
            button.Custom = command5;
            command6.Caption = "";
            command6.Enable = false;
            command6.Visibility = BarItemVisibility.Never;
            button.Delete = command6;
            command7.Caption = "";
            command7.Enable = false;
            command7.Visibility = BarItemVisibility.Never;
            button.Export = command7;
            command8.Caption = "";
            command8.Enable = false;
            command8.Visibility = BarItemVisibility.Never;
            button.Filter = command8;
            command9.Caption = "";
            command9.Enable = false;
            command9.Visibility = BarItemVisibility.Never;
            button.FilterCustomer = command9;
            command10.Caption = "";
            command10.Enable = false;
            command10.Visibility = BarItemVisibility.Never;
            button.FilterStock = command10;
            command11.Caption = "";
            command11.Enable = false;
            command11.Visibility = BarItemVisibility.Never;
            button.Find = command11;
            button.GClose = false;
            button.GCommand = false;
            button.GExport = false;
            command12.Caption = "";
            command12.Enable = false;
            command12.Visibility = BarItemVisibility.Never;
            button.Go = command12;
            button.GOption = false;
            button.GPrint = false;
            button.GRecords = false;
            button.GSearchBar = false;
            button.GSettings = false;
            button.GVaildation = false;
            command13.Caption = "";
            command13.Enable = false;
            command13.Visibility = BarItemVisibility.Never;
            button.Import = command13;
            command14.Caption = "";
            command14.Enable = false;
            command14.Visibility = BarItemVisibility.Never;
            button.Next = command14;
            command15.Caption = "";
            command15.Enable = false;
            command15.Visibility = BarItemVisibility.Never;
            button.PageSetup = command15;
            button.PHome = false;
            command16.Caption = "";
            command16.Enable = false;
            command16.Visibility = BarItemVisibility.Never;
            button.Previous = command16;
            command17.Caption = "";
            command17.Enable = false;
            command17.Visibility = BarItemVisibility.Never;
            button.Print = command17;
            command18.Caption = "";
            command18.Enable = false;
            command18.Visibility = BarItemVisibility.Never;
            button.PrintPreview = command18;
            button.PTool = false;
            command19.Caption = "";
            command19.Enable = false;
            command19.Visibility = BarItemVisibility.Never;
            button.Redo = command19;
            command20.Caption = "";
            command20.Enable = false;
            command20.Visibility = BarItemVisibility.Never;
            button.Refresh = command20;
            command21.Caption = "";
            command21.Enable = false;
            command21.Visibility = BarItemVisibility.Never;
            button.Save = command21;
            command22.Caption = "";
            command22.Enable = false;
            command22.Visibility = BarItemVisibility.Never;
            button.SaveAndClose = command22;
            command23.Caption = "";
            command23.Enable = false;
            command23.Visibility = BarItemVisibility.Never;
            button.SaveAndNew = command23;
            command24.Caption = "";
            command24.Enable = false;
            command24.Visibility = BarItemVisibility.Never;
            button.Search = command24;
            command25.Caption = "";
            command25.Enable = false;
            command25.Visibility = BarItemVisibility.Never;
            button.SearchText = command25;
            command26.Caption = "";
            command26.Enable = false;
            command26.Visibility = BarItemVisibility.Never;
            button.Task = command26;
            command27.Caption = "";
            command27.Enable = false;
            command27.Visibility = BarItemVisibility.Never;
            button.Undo = command27;
            command28.Caption = "";
            command28.Enable = false;
            command28.Visibility = BarItemVisibility.Never;
            button.Vaildate = command28;
            command29.Caption = "";
            command29.Enable = false;
            command29.Visibility = BarItemVisibility.Never;
            button.View = command29;
            this.ucAdd.RibbonBar = button;
            this.ucAdd.Size = new Size(0x14b, 0xa8);
            this.ucAdd.Status = Actions.Add;
            this.ucAdd.TabIndex = 0;
            this.ucAdd.Title = "";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x249, 0x1a7);
            base.Controls.Add(this.ucAdd);
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "xfmRewardAdd";
            base.ShowIcon = false;
            base.ShowInTaskbar = false;
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "Khen Thưởng";
            base.ResumeLayout(false);
        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            switch (keyData)
            {
                case Keys.Escape:
                    base.Close();
                    return true;

                case Keys.F2:
                    this.ucAdd.IsClose = CloseOrNew.Close;
                    this.ucAdd.Save();
                    return true;

                case (Keys.Control | Keys.S):
                    this.ucAdd.IsClose = CloseOrNew.Close;
                    this.ucAdd.Save();
                    return true;

                case (Keys.Control | Keys.W):
                    this.ucAdd.IsClose = CloseOrNew.Close;
                    this.ucAdd.Save();
                    return true;

                case (Keys.Control | Keys.Shift | Keys.S):
                    this.ucAdd.IsClose = CloseOrNew.New;
                    this.ucAdd.Save();
                    return true;

                case (Keys.Alt | Keys.D):
                    return true;

                case (Keys.Alt | Keys.X):
                    base.Close();
                    return true;
            }
            return false;
        }

        public void RaiseAddedEventHander(HRM_REWARD Item)
        {
            if (this.Added != null)
            {
                this.Added(this, Item);
            }
        }

        public void RaiseUpdatedEventHander(HRM_REWARD Item)
        {
            if (this.Updated != null)
            {
                this.Updated(this, Item);
            }
        }

        private void ucAdd_CancelClick(object sender)
        {
            base.Close();
        }

        private void ucAdd_Success(object sender, HRM_REWARD Item)
        {
            if (this.ucAdd.Status == Actions.Add)
            {
                this.RaiseAddedEventHander(Item);
            }
            else if (this.ucAdd.Status == Actions.Update)
            {
                this.RaiseUpdatedEventHander(Item);
            }
            if (this.ucAdd.IsClose == CloseOrNew.Close)
            {
                base.Close();
            }
            this.ucAdd.Clear();
        }

        public delegate void AddedEventHander(object sender, HRM_REWARD Item);

        public delegate void UpdatedEventHander(object sender, HRM_REWARD Item);
    }
}

